//
//  TSHomeScene.m
//  TaShuo
//
//  Created by N-X on 2018/1/17.
//  Copyright © 2018年 MRNAN. All rights reserved.
//

#import "TSHomeScene.h"
#import "TSHomeController.h"


@interface TSHomeScene ()
@property (nonatomic ,strong)TSHomeController * homeVC;
@end

@implementation TSHomeScene

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configuration];
//    [self setUpNavigationBar];
    [self fetchData];
}

- (void)configuration
{
    self.view.backgroundColor = KWhiteColor;
    self.homeVC = [TSHomeController instanceWithPresenter:[TSHomePresenter new]];
}

//- (void)setUpNavigationBar
//{
//    UIButton * locationbBtn = [[UIButton alloc]init];//WithFrame:CGRectMake(0, 0, 90, 25)];
//    [locationbBtn setTitle:@"洛杉矶" forState:UIControlStateNormal];
//    locationbBtn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
//    locationbBtn.titleLabel.font = [UIFont systemFontOfSize:14];
//    [locationbBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [locationbBtn setImage:[UIImage imageNamed:@"locationIcon"] forState:UIControlStateNormal];
//    [locationbBtn sizeToFit];
//    [locationbBtn layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleImageLeft imageTitlespace:2];
//
//    [locationbBtn addTarget:self action:@selector(locationAction) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc]initWithCustomView:locationbBtn];
//    UIBarButtonItem * flexItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
//    self.navigationItem.leftBarButtonItems = @[leftItem];
//    //    self.locationButton = locationbBtn;
//
//    FHNavigationBarScanView * scanView = [[FHNavigationBarScanView alloc]initWithFrame:CGRectMake(0, 0, 35, 25)];
//    UIBarButtonItem * scanItem = [[UIBarButtonItem alloc]initWithCustomView:scanView];
//    self.navigationItem.rightBarButtonItems = @[scanItem];
//
//    FHNavigationBarSearchView * searchView = [[FHNavigationBarSearchView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth * 0.7, 35)];
//    self.navigationItem.titleView = searchView;
//}
- (void)setUpUI
{
    self.homeVC.collectionView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
    [self.view addSubview:self.homeVC.collectionView];
}

- (void)fetchData
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    kWeakSelf(self)
    [self.homeVC.presenter fetchDataWithCompletionHandle:^(NSError *error, id responseJson, BOOL isCache) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:weakself.view animated:YES];
            if (!error) {
                [weakself setUpUI];
            }
        });
    }];
}



@end
